
//
//  BanBu_LoginViewController.m
//  BanBu
//
//  Created by jie zheng on 12-7-5.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "BanBu_LoginViewController.h"
#import "BanBu_ForgetPWController.h"
#import "TKLoadingView.h"
#import "AppCommunicationManager.h"
#import "BanBu_LocationManager.h"
#import "BanBu_AppDelegate.h"
#import "AppDataManager.h"
#import "BanBu_RegViewController.h"
#import "QVerifyWebViewController.h"

#import "UIDevice+Helper.h"
#import "BanBu_ImageView.h"
#import "BanBu_NavButton.h"
#import "SFHFKeychainUtils.h"
#import "UIViewController+Animation.h"
#import "BanBu_UpgradeDataBase.h"

@interface BanBu_LoginViewController ()

@end

@implementation BanBu_LoginViewController

- (id)init
{
    self = [super initWithStyle:UITableViewStyleGrouped];
    if (self) {
        // Custom initialization
    }
    return self;
}

-(void)dealloc{
    [[NSNotificationCenter defaultCenter]removeObserver:self name:SCSessionStateChangedNotification object:nil];
    [[NSNotificationCenter defaultCenter]removeObserver:self name:@"Twitter" object:nil];
    
    [super dealloc];
}
-(void)popself
{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)showThirdLogin//界面
{
    UIView *aView = [[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 160)] autorelease];
    aView.backgroundColor = [UIColor clearColor];
    self.tableView.tableFooterView = aView;
    _rows = 0;
    [self.tableView reloadData];
}
-(void)initSubViews//界面
{
    UIView *aView = [[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 40)]autorelease];
    aView.backgroundColor = [UIColor clearColor];
    self.tableView.tableFooterView = aView;
    
    self.title = NSLocalizedString(@"loginTitle", nil);
    self.tableView.backgroundView = nil;
    self.tableView.backgroundColor = [UIColor colorWithRed:255.0/255 green:250.0/255 blue:240.0/255 alpha:1.0];
    BanBu_NavButton *completeButton = [[BanBu_NavButton alloc] initWithButtonType:UIButtonCreatTypeNormal];
    completeButton.position = ButtonPositionRight;
    [completeButton addTarget:self action:@selector(login:) forControlEvents:UIControlEventTouchUpInside];
    CGFloat btnLen = [NSLocalizedString(@"logButton", nil) sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:CGSizeMake(100, 30)].width;
    
    completeButton.frame=CGRectMake(0, 0, btnLen+20, 30);
    //    [completeButton setTitleEdgeInsets:UIEdgeInsetsMake(3, 2, 2, 2)];
    [completeButton setTitle:NSLocalizedString(@"logButton", nil) forState:UIControlStateNormal];
    completeButton.titleLabel.font = [UIFont systemFontOfSize:14];
    UIBarButtonItem *complete = [[[UIBarButtonItem alloc] initWithCustomView:completeButton] autorelease];
    self.navigationItem.rightBarButtonItem = complete;
    [completeButton release];
    
    BanBu_ImageView *img = [[[BanBu_ImageView alloc] initWithBackGroundImageType:UIImageViewCreatTypeTable] autorelease];
    self.tableView.backgroundView = img;
    
    NSString *langauage=[MyAppDataManager getPreferredLanguage];
    if(![langauage isEqual:@"zh-Hans"]){
        [self showThirdLogin];
        _rows = 0;
    }else{
        _rows = 2;
    }
    
    NSString *forgetString = NSLocalizedString(@"forgetPassword", nil);
    CGFloat width = [forgetString sizeWithFont:[UIFont systemFontOfSize:16] constrainedToSize:CGSizeMake(280, 35) lineBreakMode:kTextLineBreakByWordWrapping].width;
    forgetBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [forgetBtn setTitle:forgetString forState:UIControlStateNormal];
    forgetBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [forgetBtn setTitleColor:[UIColor colorWithRed:50.0/255 green:79.0/255 blue:133.0/255 alpha:1.0] forState:UIControlStateNormal];
    //    forgetBtn.titleLabel.textColor = [UIColor colorWithRed:50.0/255 green:79.0/255 blue:133.0/255 alpha:1.0];
    [forgetBtn addTarget:self action:@selector(resetPassword) forControlEvents:UIControlEventTouchUpInside];
    forgetBtn.frame = CGRectMake(300-width, 150, width+20, 35);
    forgetBtn.hidden = YES;
    [self.tableView addSubview:forgetBtn];
    
}
-(void)resetPassword
{
    BanBu_ForgetPWController *forgetPW = [[BanBu_ForgetPWController alloc] init];
    [self.navigationController pushViewController:forgetPW animated:YES];
    [forgetPW release];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    [self initSubViews];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(sessionStateChanged:) name:SCSessionStateChangedNotification object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(checkTwitterGO:) name:@"Twitter" object:nil];
    
   }

-(void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    [self.twitterEngine loadAccessToken];
    _twitterLoginID = self.twitterEngine.loggedInID;
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [AppComManager cancalHandlesForObject:self];
    [TKLoadingView dismissTkFromView:self.navigationController.view animated:NO afterShow:0.0];
    
}

-(void)showLoginField{
    //    self.tableView.tableFooterView.hidden = YES;
    
    //    _rows = 2;
    //    [self.tableView reloadData];
    
}


/*
-(void)populateUserDetails:(FBSession *)session{
    
    if([FBSession activeSession].isOpen){
        [TKLoadingView showTkloadingAddedTo:self.navigationController.view title:NSLocalizedString(@"loadingNotice", nil) activityAnimated:YES];
        //        self.navigationController.view.userInteractionEnabled = NO;
        [[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connectin, NSDictionary<FBGraphUser> *myuser, NSError *error){
            
            if(!error){
                [UserDefaults setValue:[session accessToken] forKey:@"FBUser"];
                [MyAppDataManager.regDic setValue:myuser.first_name forKey:@"pname"];
                [MyAppDataManager.regDic setValue:[myuser objectForKey:@"email"] forKey:@"email"];
                [MyAppDataManager.regDic setValue:[[myuser objectForKey:@"gender"] substringToIndex:1] forKey:@"gender"];
                NSArray *birthArr = [myuser.birthday componentsSeparatedByString:@"/"];
                NSString *birthStr = [NSString stringWithFormat:@"%@-%@-%@",[birthArr objectAtIndex:2],[birthArr objectAtIndex:1],[birthArr objectAtIndex:0]];
                [MyAppDataManager.regDic setValue:birthStr forKey:@"borndate"];
                [MyAppDataManager.regDic setValue:@"b" forKey:@"regby"];
                
                NSMutableDictionary *loginDic = [NSMutableDictionary dictionary];
                [loginDic setValue:[myuser objectForKey:@"email"] forKey:@"email"];
                [loginDic setValue:[NSString stringWithFormat:@"%.f",AppLocationManager.curLocation.latitude*1000000] forKey:@"plat"];
                [loginDic setValue:[NSString stringWithFormat:@"%.f",AppLocationManager.curLocation.longitude*1000000] forKey:@"plong"];
                [loginDic setValue:[UserDefaults valueForKey:@"pushid"] forKey:@"pushid"];
                NSString *isJailbroken = nil;
                if([[UIDevice currentDevice] isJailbroken]){
                    isJailbroken = @"YES";
                }else{
                    isJailbroken = @"NO";
                }
                NSError *error;
                CFUUIDRef puuid = CFUUIDCreate( nil );
                CFStringRef uuidString = CFUUIDCreateString( nil, puuid );
                NSString * result = (NSString *)CFStringCreateCopy( NULL, uuidString);
                CFRelease(puuid);
                CFRelease(uuidString);
                if(![[SFHFKeychainUtils getPasswordForUsername:@"halfeet_user_UUID" andServiceName:@"com.halfeet_halfeet" error:&error] length])
                {
                    [SFHFKeychainUtils storeUsername:@"halfeet_user_UUID" andPassword:result forServiceName:@"com.halfeet_halfeet" updateExisting:YES error:&error];
                }
               
                
                NSString *systemUDID = [SFHFKeychainUtils getPasswordForUsername:@"halfeet_user_UUID" andServiceName:@"com.halfeet_halfeet" error:&error];
                [loginDic setValue:[NSString stringWithFormat:@"%@::%@::%@::%@::%@::%@",[[UIDevice currentDevice] systemName],[[UIDevice currentDevice] systemVersion],[MyAppDataManager getPreferredLanguage],[[UIDevice currentDevice] platformString],isJailbroken,systemUDID] forKey:@"sysparam"];
                
                NSMutableDictionary *dic = [NSMutableDictionary dictionary];
                [dic setValue:[[UIDevice currentDevice] systemVersion] forKey:@"osver"];
                NSString *deviceStr = [[UIDevice currentDevice] platformString];
                NSString *dev = nil;
                NSString *isp = nil;
                if([deviceStr rangeOfString:@"("].location != NSNotFound&&[deviceStr rangeOfString:@")"].location != NSNotFound)
                {
                    isp = [deviceStr substringFromIndex:[deviceStr rangeOfString:@"("].location];
                    dev = [deviceStr substringToIndex:[deviceStr rangeOfString:@"("].location];
                }
                //    NSLog(@"%@ %@",isp,dev);
                [dic setValue:isp forKey:@"isp"];
                [dic setValue:dev forKey:@"dev"];
                
                [dic setValue:[[UIDevice currentDevice] name] forKey:@"name"];
                [dic setValue:isJailbroken forKey:@"jail"];
                [loginDic setValue:dic forKey:@"phoneinfor"];
               
                
                [loginDic setValue:[MyAppDataManager getLanguageSubmitToServer] forKey:@"lang"];
                
                //判读是什么绑定的
                _bindType = 1;
                //yinlinlin 2014年08月08日15:24:12 先使用pushid，获取不到的情况下使用systemUDID
                BanBu_AppDelegate *ap = (BanBu_AppDelegate *)[UIApplication sharedApplication].delegate;
                
                if(ap.pushid&&ap.pushid.length)
                {
                    [loginDic setValue:ap.pushid forKey:@"deviceid"];
                }
                else
                {
                    
                    [loginDic setValue:systemUDID forKey:@"deviceid"];
                }

                
                NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleVersionKey];
                [loginDic setValue:version forKey:@"version"];
                NSLog(@"%@",loginDic);
                
                [AppComManager getBanBuData:BanBu_Check_Login_Bind par:loginDic delegate:self];
                [TKLoadingView showTkloadingAddedTo:self.navigationController.view title:NSLocalizedString(@"chuliNotice", nil) activityAnimated:YES];
                
                
                //                [TKLoadingView dismissTkFromView:self.view animated:NO afterShow:0.0];
                //                self.navigationController.view.userInteractionEnabled = YES;
                
                //                [[FBSession activeSession]closeAndClearTokenInformation];
                
                
            }
            else{
                [TKLoadingView dismissTkFromView:self.navigationController.view animated:NO afterShow:0.0];
                self.navigationController.view.userInteractionEnabled = YES;
            }
        }];
        
    }
}
*/
- (void)sessionStateChanged:(NSNotification*)notification {
    // A more complex app might check the state to see what the appropriate course of
    // action is, but our needs are simple, so just make sure our idea of the session is
    // up to date and repopulate the user's name and picture (which will fail if the session
    // has become invalid).
   // [self performSelector:@selector(populateUserDetails:) withObject:(FBSession *)[notification object]];
    //    FBSession *aS = [notification object];
    
}

-(void)checkTwitterGO:(NSNotification *)noti{
    
    [MyAppDataManager.regDic setValue:[UserDefaults valueForKey:@"TUser"] forKey:@"pname"];
    [MyAppDataManager.regDic setValue:[NSString stringWithFormat:@"%@@twitter.com",[noti object]] forKey:@"email"];
    
    [MyAppDataManager.regDic setValue:@"b" forKey:@"regby"];
    
    NSMutableDictionary *loginDic = [NSMutableDictionary dictionary];
    [loginDic setValue:[MyAppDataManager.regDic objectForKey:@"email"] forKey:@"email"];
    [loginDic setValue:[NSString stringWithFormat:@"%.f",AppLocationManager.curLocation.latitude*1000000] forKey:@"plat"];
    [loginDic setValue:[NSString stringWithFormat:@"%.f",AppLocationManager.curLocation.longitude*1000000] forKey:@"plong"];
    //获取手机信息
    NSString * stringPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSString * documentFile = [stringPath stringByAppendingPathComponent:@"one"];
    if (![[NSFileManager defaultManager] fileExistsAtPath:documentFile]){
        NSString *isJailbroken = nil;
        if([[UIDevice currentDevice] isJailbroken]){
            isJailbroken = @"YES";
        }else{
            isJailbroken = @"NO";
        }
        
        NSError *error;
        CFUUIDRef puuid = CFUUIDCreate( nil );
        CFStringRef uuidString = CFUUIDCreateString( nil, puuid );
        NSString * result = (NSString *)CFStringCreateCopy( NULL, uuidString);
        CFRelease(puuid);
        CFRelease(uuidString);
        if(![[SFHFKeychainUtils getPasswordForUsername:@"halfeet_user_UUID" andServiceName:@"com.halfeet_halfeet" error:&error] length])
        {
            [SFHFKeychainUtils storeUsername:@"halfeet_user_UUID" andPassword:result forServiceName:@"com.halfeet_halfeet" updateExisting:YES error:&error];
        }
        NSString *systemUDID = [SFHFKeychainUtils getPasswordForUsername:@"halfeet_user_UUID" andServiceName:@"com.halfeet_halfeet" error:&error];
        
        //        NSLog(@"systemUDID--------::%@",systemUDID);
        [loginDic setValue:[NSString stringWithFormat:@"%@::%@::%@::%@::%@::%@",[[UIDevice currentDevice] systemName],[[UIDevice currentDevice] systemVersion],[MyAppDataManager getPreferredLanguage],[[UIDevice currentDevice] platformString],isJailbroken,systemUDID] forKey:@"sysparam"];
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
        [dic setValue:[[UIDevice currentDevice] systemVersion] forKey:@"osver"];
        NSString *deviceStr = [[UIDevice currentDevice] platformString];
        NSString *dev = nil;
        NSString *isp = nil;
        if([deviceStr rangeOfString:@"("].location != NSNotFound&&[deviceStr rangeOfString:@")"].location != NSNotFound)
        {
            isp = [deviceStr substringFromIndex:[deviceStr rangeOfString:@"("].location];
            dev = [deviceStr substringToIndex:[deviceStr rangeOfString:@"("].location];
        }
        //    NSLog(@"%@ %@",isp,dev);
        [dic setValue:isp forKey:@"isp"];
        [dic setValue:dev forKey:@"dev"];
        
        [dic setValue:[[UIDevice currentDevice] name] forKey:@"name"];
        [dic setValue:isJailbroken forKey:@"jail"];
        [loginDic setValue:dic forKey:@"phoneinfor"];
        
        //yinlinlin 2014年08月08日15:24:12 先使用pushid，获取不到的情况下使用systemUDID
        BanBu_AppDelegate *ap = (BanBu_AppDelegate *)[UIApplication sharedApplication].delegate;
        
        if(ap.pushid&&ap.pushid.length)
        {
            [loginDic setValue:ap.pushid forKey:@"deviceid"];
        }
        else
        {
            [loginDic setValue:systemUDID forKey:@"deviceid"];
        }

        
        [loginDic setValue:[MyAppDataManager getLanguageSubmitToServer] forKey:@"lang"];
        
        
    }
    
    [loginDic setValue:[UserDefaults valueForKey:@"pushid"] forKey:@"pushid"];
    
    
    
    NSString *isJailbroken = nil;
    if([[UIDevice currentDevice] isJailbroken]){
        isJailbroken = @"YES";
    }else{
        isJailbroken = @"NO";
    }
    
    NSError *error;
    CFUUIDRef puuid = CFUUIDCreate( nil );
    CFStringRef uuidString = CFUUIDCreateString( nil, puuid );
    NSString * result = (NSString *)CFStringCreateCopy( NULL, uuidString);
    CFRelease(puuid);
    CFRelease(uuidString);
    if(![[SFHFKeychainUtils getPasswordForUsername:@"halfeet_user_UUID" andServiceName:@"com.halfeet_halfeet" error:&error] length])
    {
        [SFHFKeychainUtils storeUsername:@"halfeet_user_UUID" andPassword:result forServiceName:@"com.halfeet_halfeet" updateExisting:YES error:&error];
    }
   
    
    //    NSLog(@"systemUDID--------::%@",systemUDID);
    NSString *systemUDID = [SFHFKeychainUtils getPasswordForUsername:@"halfeet_user_UUID" andServiceName:@"com.halfeet_halfeet" error:&error];
    [loginDic setValue:[NSString stringWithFormat:@"%@::%@::%@::%@::%@::%@",[[UIDevice currentDevice] systemName],[[UIDevice currentDevice] systemVersion],[MyAppDataManager getPreferredLanguage],[[UIDevice currentDevice] platformString],isJailbroken,systemUDID] forKey:@"sysparam"];
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setValue:[[UIDevice currentDevice] systemVersion] forKey:@"osver"];
    NSString *deviceStr = [[UIDevice currentDevice] platformString];
    NSString *dev = nil;
    NSString *isp = nil;
    if([deviceStr rangeOfString:@"("].location != NSNotFound&&[deviceStr rangeOfString:@")"].location != NSNotFound)
    {
        isp = [deviceStr substringFromIndex:[deviceStr rangeOfString:@"("].location];
        dev = [deviceStr substringToIndex:[deviceStr rangeOfString:@"("].location];
    }
    //    NSLog(@"%@ %@",isp,dev);
    [dic setValue:isp forKey:@"isp"];
    [dic setValue:dev forKey:@"dev"];
    
    [dic setValue:[[UIDevice currentDevice] name] forKey:@"name"];
    [dic setValue:isJailbroken forKey:@"jail"];
    [loginDic setValue:dic forKey:@"phoneinfor"];
    
    //yinlinlin 2014年08月08日15:24:12 先使用pushid，获取不到的情况下使用systemUDID
    BanBu_AppDelegate *ap = (BanBu_AppDelegate *)[UIApplication sharedApplication].delegate;
    
    if(ap.pushid&&ap.pushid.length)
    {
        [loginDic setValue:ap.pushid forKey:@"deviceid"];
    }
    else
    {
    
        [loginDic setValue:systemUDID forKey:@"deviceid"];
    }
    
    [loginDic setValue:[MyAppDataManager getLanguageSubmitToServer] forKey:@"lang"];
    //根据语言，登陆时的提示；
    //    NSString *langauage=[[MyAppDataManager getPreferredLanguage]substringToIndex:2];
    //
    //    if([langauage isEqual:@"zh"]){
    //        [loginDic setValue:@"cn" forKey:@"lang"];
    //
    //    }else if([langauage isEqual:@"ja"]){
    //        [loginDic setValue:@"jp" forKey:@"lang"];
    //    }else{
    //        [loginDic setValue:@"en" forKey:@"lang"];
    //    }
    [loginDic setValue:[MyAppDataManager getLanguageSubmitToServer] forKey:@"lang"];
    NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleVersionKey];
    [loginDic setValue:version forKey:@"version"];
    
    //判读是什么绑定的
    _bindType = 2;
    [AppComManager getBanBuData:BanBu_Check_Login_Bind par:loginDic delegate:self];
    [TKLoadingView showTkloadingAddedTo:self.navigationController.view title:NSLocalizedString(@"chuliNotice", nil) activityAnimated:YES];
    
}

#pragma mark -用户登录传入参数 "email"  "pass"
- (void)login:(UIButton *)button
{
    if(!_userName.text.length)
    {
        [TKLoadingView showTkloadingAddedTo:self.view title:NSLocalizedString(@"userNameNil", nil) activityAnimated:NO duration:2.0];
        return;
    }
    if(_userpw.text.length<6)
    {
        [TKLoadingView showTkloadingAddedTo:self.view title:NSLocalizedString(@"passWordError", nil) activityAnimated:NO duration:2.0];
        return;
    }
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:_userName.text,@"email",_userpw.text,@"pass",nil];
    
    [self loginRequest:dic];
    
    [MyAppDataManager initDetailChatMessageTable];
    
}
/*//用户登录校验
 网址　http://www.koochat.com/_user_login/_check_user_login.php?jsonfrom=
 参数　{"fc":"check_user_login","email":"abcd123456@gmail.com","pass":"123456","plong":"118113314","plat":"40019923"}
 返回　{"fc":"check_user_login","logok":"y","loginid":"20120707212149-3E4227CB-2D3E-A6D5-A656-BA755B231D71","serveron":"127.0.0.1"}
 
 email值为用户邮箱，pass值为用户
 long值为经度, lat值为纬度
 logok值为y表示登录成功，值为n表示登录失败
 loginid值为登录ID，供后期调用时向服务器端提交此值
 serveron值为分配的服务器，部分接口功能需发送请求到该返回值指定的服务器*/

- (void)loginRequest:(NSDictionary *)_nameAndPassWd
{
    NSMutableDictionary *loginDic = [NSMutableDictionary dictionary];
    
    [loginDic addEntriesFromDictionary:_nameAndPassWd];
    
    [loginDic setValue:[NSString stringWithFormat:@"%.f",AppLocationManager.curLocation.latitude*1000000] forKey:@"plat"];
    [loginDic setValue:[NSString stringWithFormat:@"%.f",AppLocationManager.curLocation.longitude*1000000] forKey:@"plong"];
    [loginDic setValue:[UserDefaults valueForKey:@"pushid"] forKey:@"pushid"];
    NSString *isJailbroken = nil;
    if([[UIDevice currentDevice] isJailbroken]){
        isJailbroken = @"YES";
    }else{
        isJailbroken = @"NO";
    }
    NSError *error;
    CFUUIDRef puuid = CFUUIDCreate( nil );
    CFStringRef uuidString = CFUUIDCreateString( nil, puuid );
    NSString * result = (NSString *)CFStringCreateCopy( NULL, uuidString);
    CFRelease(puuid);
    CFRelease(uuidString);
    if(![[SFHFKeychainUtils getPasswordForUsername:@"halfeet_user_UUID" andServiceName:@"com.halfeet_halfeet" error:&error] length])
    {
        [SFHFKeychainUtils storeUsername:@"halfeet_user_UUID" andPassword:result forServiceName:@"com.halfeet_halfeet" updateExisting:YES error:&error];
    }
   
    NSString *systemUDID = [SFHFKeychainUtils getPasswordForUsername:@"halfeet_user_UUID" andServiceName:@"com.halfeet_halfeet" error:&error];
    [loginDic setValue:[NSString stringWithFormat:@"%@::%@::%@::%@::%@::%@",[[UIDevice currentDevice] systemName],[[UIDevice currentDevice] systemVersion],[MyAppDataManager getPreferredLanguage],[[UIDevice currentDevice] platformString],isJailbroken,systemUDID] forKey:@"sysparam"];
    //    NSLog(@"%@",[NSString stringWithFormat:@"%@::%@::%@::%@::%@::%@",[[UIDevice currentDevice] systemName],[[UIDevice currentDevice] systemVersion],[MyAppDataManager getPreferredLanguage],[[UIDevice currentDevice] platformString],isJailbroken,systemUDID]);
    //    NSLog(@"%@",[[UIDevice currentDevice] platformString]);
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setValue:[[UIDevice currentDevice] systemVersion] forKey:@"osver"];
    NSString *deviceStr = [[UIDevice currentDevice] platformString];
    NSString *dev = nil;
    NSString *isp = nil;
    if([deviceStr rangeOfString:@"("].location != NSNotFound&&[deviceStr rangeOfString:@")"].location != NSNotFound)
    {
        isp = [deviceStr substringFromIndex:[deviceStr rangeOfString:@"("].location];
        dev = [deviceStr substringToIndex:[deviceStr rangeOfString:@"("].location];
    }
    //    NSLog(@"%@ %@",isp,dev);
    [dic setValue:isp forKey:@"isp"];
    [dic setValue:dev forKey:@"dev"];
    
    [dic setValue:[[UIDevice currentDevice] name] forKey:@"name"];
    [dic setValue:isJailbroken forKey:@"jail"];
    [loginDic setValue:dic forKey:@"phoneinfor"];
    
    //yinlinlin 2014年08月08日15:24:12 先使用pushid，获取不到的情况下使用systemUDID
    BanBu_AppDelegate *ap = (BanBu_AppDelegate *)[UIApplication sharedApplication].delegate;
    
    if(ap.pushid&&ap.pushid.length)
    {
        [loginDic setValue:ap.pushid forKey:@"deviceid"];
    }
    else
    {
        [loginDic setValue:systemUDID forKey:@"deviceid"];
    }

    
    [loginDic setValue:[MyAppDataManager getLanguageSubmitToServer] forKey:@"lang"];
    
    
    NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleVersionKey];
    [loginDic setValue:version forKey:@"version"];
    [AppComManager getBanBuData:BanBu_Check_Login par:loginDic delegate:self];
    self.navigationController.view.userInteractionEnabled = NO;
    [TKLoadingView showTkloadingAddedTo:self.navigationController.view title:NSLocalizedString(@"loading", nil) activityAnimated:YES];
    
    //创建10张聊天记录表
}


- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Twitter
- (void)storeAccessToken:(NSString *)accessToken
{
    [[NSUserDefaults standardUserDefaults]setObject:accessToken forKey:@"SavedAccessHTTPBody"];
}

- (NSString *)loadAccessToken {
    return [[NSUserDefaults standardUserDefaults]objectForKey:@"SavedAccessHTTPBody"];
}

#pragma mark - Table view data source

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    if(!section)
        return 2;
    else
        return 1;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    //    [cell setHighlighted:YES];
    if(cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    
    if(!indexPath.section)
    {
        UITextField *textField = (UITextField *)[cell viewWithTag:111];
        if(!textField)
        {
            textField = [[UITextField alloc] initWithFrame:CGRectMake(110, 0, 200, 44)];
            textField.delegate = self;
            textField.tag = 111;
            textField.backgroundColor = [UIColor clearColor];
            textField.borderStyle = UITextBorderStyleNone;
            textField.textColor = [UIColor colorWithRed:50.0/255 green:79.0/255 blue:133.0/255 alpha:1.0];
            textField.font = [UIFont systemFontOfSize:15];
            textField.clearButtonMode = UITextFieldViewModeWhileEditing;
            
            textField.textAlignment = kTextAlignmentLeft;
            textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
            textField.keyboardType = UIKeyboardTypeASCIICapable;
            [cell addSubview:textField];
            [textField release];
            if(!indexPath.row)
            {
                cell.textLabel.text = NSLocalizedString(@"userNameLabel", nil);
                _userName = textField;
                _userName.keyboardType = UIKeyboardTypeEmailAddress;
                _userName.placeholder = NSLocalizedString(@"userPlabeholder", nil);
                _userName.returnKeyType = UIReturnKeyDone;
                [_userName becomeFirstResponder];
                if([UserDefaults valueForKey:@"myID"]){
                    _userName.text = [UserDefaults valueForKey:@"myID"];
                    
                }
                //                _userName.text = @"10158";
                
            }
            else
            {
                
                cell.textLabel.text =NSLocalizedString(@"passwordLabel", nil);
                _userpw = textField;
                textField.placeholder =NSLocalizedString(@"pwPlaceholder", nil);
                textField.returnKeyType = UIReturnKeyGo;
                textField.secureTextEntry = YES;
                
                //                textField.text = @"123456";
            }
        }
    }
    else
    {
        //        [cell.contentView addSubview:forgetBtn];
        //        forgetBtn.backgroundColor = [UIColor redColor];
        //        forgetBtn.frame = CGRectMake(160, 5, 150, 35);
        
        //        cell.textLabel.text = @"忘记密码?";
        //        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    //    cell.selectionStyle = UITableViewCellSelectionStyleNone;// 取消选中
    return cell;
}

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(!indexPath.section)
    {
        UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        UITextField *textField = (UITextField *)[cell viewWithTag:111];
        [textField becomeFirstResponder];
        [tableView deselectRowAtIndexPath:indexPath animated:NO];
    }
    
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [super touchesBegan:touches withEvent:event];
    if([_userName isFirstResponder]){
        [_userName resignFirstResponder];
    }
    if([_userpw isFirstResponder]){
        [_userpw isFirstResponder];
    }
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if(textField.returnKeyType == UIReturnKeyGo)
    {
        [self performSelector:@selector(login:)];
    }
    return YES;
}


- (void)banbuRequestDidFinished:(NSDictionary *)resDic error:(NSError *)error
{
    NSLog(@"%@",resDic);
    self.navigationController.view.userInteractionEnabled = YES;
    [TKLoadingView dismissTkFromView:self.navigationController.view animated:YES afterShow:0.0];
    if(error)
    {
        if([error.domain isEqualToString:BanBuDataformatError])
        {
            [TKLoadingView showTkloadingAddedTo:self.navigationController.view title:NSLocalizedString(@"network_error", nil) activityAnimated:NO duration:2.0];
        }
        else
        {
            [TKLoadingView showTkloadingAddedTo:self.navigationController.view title:NSLocalizedString(@"network_error", nil) activityAnimated:NO duration:2.0];
        }
        
        return;
    }
    
    if([AppComManager respondsDic:resDic isFunctionData:BanBu_Check_Login])
    {
        [UserDefaults setValue:@"" forKey:@"QUser"];
        [UserDefaults setValue:@"" forKey:@"sinaUser"];
        [UserDefaults setValue:@"" forKey:@"FBUser"];
        [UserDefaults setValue:@"" forKey:@"TUser"];
        
        if([[resDic valueForKey:@"ok"] boolValue])
        {
            if(![[resDic objectForKey:@"bindlist"] isEqual:@""])
            {
                //绑定信息
                NSString *bindString;
                NSArray *bindArray;
                
                for(int i=0;i<[[resDic objectForKey:@"bindlist"] count];i++)
                {
                    NSDictionary *bindDic= [[resDic objectForKey:@"bindlist"] objectAtIndex:i];
                    bindString = [bindDic objectForKey:@"bindstring"];
                    bindArray= [bindString componentsSeparatedByString:@","];
                    
                    if([[bindDic objectForKey:@"bindto"]isEqualToString:@"ten_weib"] && ![bindString isEqualToString:@""])
                    {
                        [UserDefaults setValue:[bindArray objectAtIndex:0] forKey:AppTokenKey];
                        [UserDefaults setValue:[bindArray objectAtIndex:1] forKey:AppTokenSecret];
                        [UserDefaults setValue:[bindArray objectAtIndex:2] forKey:@"QUser"];
                    }
                    
                    if([[bindDic objectForKey:@"bindto"]isEqualToString:@"sina_wei"]&& ![bindString isEqualToString:@""])
                    {
                        [UserDefaults setValue:[bindArray objectAtIndex:0] forKey:@"AccessToken"];
                        [UserDefaults setValue:[bindArray objectAtIndex:1] forKey:@"sinaUser"];
                    }
                    if([[bindDic objectForKey:@"bindto"]isEqualToString:@"facebook"]&& ![bindString isEqualToString:@""])
                    {
                        [UserDefaults setValue:[bindArray objectAtIndex:0] forKey:@"FBAccessToken"];
                        [UserDefaults setValue:[bindArray objectAtIndex:1] forKey:@"FBUser"];
                    }
                    if([[bindDic objectForKey:@"bindto"]isEqualToString:@"twitter"]&& ![bindString isEqualToString:@""])
                    {
                        [UserDefaults setValue:[bindArray objectAtIndex:0] forKey:@"TAccessToken"];
                        [UserDefaults setValue:[bindArray objectAtIndex:1] forKey:@"TAccessTokenSecret"];
                        [UserDefaults setValue:[bindArray objectAtIndex:2] forKey:@"TUser"];
                    }
                }
            }
            
            MyAppDataManager.loginid = [resDic valueForKey:@"loginid"];
            MyAppDataManager.useruid = [resDic valueForKey:@"userid"];
            MyAppDataManager.userAvatar =[resDic valueForKey:@"uface"];
            NSLog(@"%@",[UserDefaults valueForKey:MyAppDataManager.useruid]);
            if([UserDefaults valueForKey:MyAppDataManager.useruid]&&![[UserDefaults valueForKey:MyAppDataManager.useruid] isKindOfClass:[NSDictionary class]])
            {
                [UserDefaults setValue:[NSDictionary dictionary] forKey:MyAppDataManager.useruid];
            }
            //            [UserDefaults setValue:<#(id)#> forKey:MyAppDataManager.useruid];
            if(![[UserDefaults valueForKey:MyAppDataManager.useruid] valueForKey:@"settings"])
            {
                NSMutableDictionary *settingsDic = [NSMutableDictionary dictionaryWithCapacity:2];
                [settingsDic setValue:[NSArray arrayWithObjects:[NSNumber numberWithBool:YES],[NSNumber numberWithBool:YES], nil] forKey:@"boolKey"];
                [settingsDic setValue:@"msg_1" forKey:@"MusicSwith"];
                [settingsDic setValue:@"send_0" forKey:@"sendMsgBoolKey"];//添加发消息声音提示
                [settingsDic setValue:[NSNumber numberWithBool:YES] forKey:@"systemset_friendreadstatus"];//发送消息已读状态设置
                [settingsDic setValue:[NSNumber numberWithBool:NO] forKey:@"setFollowsHidden"];//隐藏关注的人，默认为否，不隐藏
                
                [settingsDic setValue:[resDic valueForKey:@"hideme"] forKey:@"hideme"];
                NSMutableDictionary *addDic = [NSMutableDictionary dictionaryWithDictionary:resDic];
                [addDic setValue:settingsDic forKey:@"settings"];
                [UserDefaults setValue:addDic forKey:MyAppDataManager.useruid];
            }
            else
            {
                NSMutableDictionary *settingsDic = [NSMutableDictionary dictionaryWithDictionary:[[UserDefaults valueForKey:MyAppDataManager.useruid] valueForKey:@"settings"]];
                [settingsDic setValue:[resDic valueForKey:@"hideme"] forKey:@"hideme"];
                NSMutableDictionary *addDic = [NSMutableDictionary dictionaryWithDictionary:resDic];
                [addDic setValue:settingsDic forKey:@"settings"];
                [UserDefaults setValue:addDic forKey:MyAppDataManager.useruid];
            }
            
            BOOL bl = [BanBu_UpgradeDataBase backupDB];
            if (bl)
            {
                NSLog(@"数据库升级完成");
            }
            
            //添加三个系统通知设置
            if(![[[UserDefaults valueForKey:MyAppDataManager.useruid] valueForKey:@"settings"] valueForKey:@"visitYouNotification"])
            {
                NSMutableDictionary *settingsDic = [NSMutableDictionary dictionaryWithDictionary:[[UserDefaults valueForKey:MyAppDataManager.useruid] valueForKey:@"settings"]];
                
                [settingsDic setValue:[NSNumber numberWithBool:YES] forKey:@"visitYouNotification"];   //接收“我查看了你的个人资料”通知
                [settingsDic setValue:[NSNumber numberWithBool:YES] forKey:@"followYouNotification"];  //接收“我关注了你”通知
                [settingsDic setValue:[NSNumber numberWithBool:YES] forKey:@"takeCareNotification"];   //接收新用户注册通知
                
                NSMutableDictionary *addDic = [NSMutableDictionary dictionaryWithDictionary:[UserDefaults valueForKey:MyAppDataManager.useruid]];
                [addDic setValue:settingsDic forKey:@"settings"];
                [UserDefaults setValue:addDic forKey:MyAppDataManager.useruid];
            }
            
            //是否删除聊天表
            if (![[[[UserDefaults valueForKey:MyAppDataManager.useruid] valueForKey:@"settings"] valueForKey:@"onceRun"] boolValue])
            {
                //保存版本号
                NSString  *versonPath =[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0] stringByAppendingPathComponent:@"data.dat"];
                
                NSMutableDictionary * versonDic = [NSKeyedUnarchiver unarchiveObjectWithFile:versonPath];
                NSString * versonString = [versonDic valueForKey:MyAppDataManager.useruid];
                NSInteger versonNum = [versonString integerValue];
                
                //当前版本
                versonString = MyAppDataManager.newVersionNumber;
                versonString = [versonString stringByReplacingOccurrencesOfString:@"." withString:@""];
                
                NSInteger newVerson = [[MyAppDataManager.newVersionNumber stringByReplacingOccurrencesOfString:@"." withString:@""] integerValue];
                
                if (newVerson > 100)
                {
                    newVerson /= 10;
                }
                if (versonNum > 100)
                {
                    versonNum /= 10;
                }
                
                if (versonNum < newVerson )//1.5.1 :15;1.6.1:16；如果1.6：16，1.6.1：16；两者相等，如果没有旧版本号，说明是新登录的，直接更新
                {
                    //1备份数据库（chat_130026_0 被分为chat_130026_0_bak,talkPeoples130026被分为talkPeoples130026_bak等等）
                    BOOL bl = [BanBu_UpgradeDataBase backupDB];
                    if (bl)
                    {
                        NSLog(@"数据库升级完成");
                    }
                }
                
                //保存当前本版号
                [versonDic setValue:versonString forKey:MyAppDataManager.useruid];
                NSData *listData=[NSKeyedArchiver archivedDataWithRootObject:versonDic];
                [listData writeToFile:versonPath atomically:YES];
                
                NSMutableDictionary * settingDic = [NSMutableDictionary dictionaryWithDictionary:[[UserDefaults valueForKey:MyAppDataManager.useruid] valueForKey:@"settings"]];
                
                [settingDic setValue:[NSNumber numberWithBool:1] forKey:@"onceRun"];
                NSMutableDictionary * dic =[NSMutableDictionary dictionaryWithDictionary:[UserDefaults valueForKey:MyAppDataManager.useruid]];
                [dic setValue:settingDic forKey:@"settings"];
                
                [UserDefaults setValue:dic forKey:MyAppDataManager.useruid];
            }
            //创建10张聊天记录表
            [MyAppDataManager initDetailChatMessageTable];
            [UserDefaults setValue:MyAppDataManager.useruid forKey:@"myID"];
            
            [UserDefaults synchronize];
            [UserDefaults setValue:[resDic valueForKey:@"friendlist"] forKey:FriendShip];
            
            BanBu_AppDelegate *delegate = (BanBu_AppDelegate *)[UIApplication sharedApplication].delegate;
            delegate.logined = YES;
            [delegate setViewController:YES];
        }
        else
        {
            [TKLoadingView showTkloadingAddedTo:self.navigationController.view title:NSLocalizedString(@"userNameOrpassWordError", nil) activityAnimated:NO duration:2.0];
            [TKLoadingView showTkloadingAddedTo:self.navigationController.view title:[MyAppDataManager IsInternationalLanguage:[resDic valueForKey:@"error"]] activityAnimated:NO duration:2.0];
        }
    }
    else if([AppComManager respondsDic:resDic isFunctionData:BanBu_Check_Login_Bind])
    {
        if([[resDic valueForKey:@"ok"] boolValue])
        {
            MyAppDataManager.loginid = [resDic valueForKey:@"loginid"];
            MyAppDataManager.useruid = [resDic valueForKey:@"userid"];
            MyAppDataManager.userAvatar =[resDic valueForKey:@"uface"];
            
            if(![[UserDefaults valueForKey:MyAppDataManager.useruid] valueForKey:@"settings"])
            {
                NSMutableDictionary *settingsDic = [NSMutableDictionary dictionaryWithCapacity:2];
                [settingsDic setValue:[NSArray arrayWithObjects:[NSNumber numberWithBool:YES],[NSNumber numberWithBool:YES], nil] forKey:@"boolKey"];
                [settingsDic setValue:@"msg_1" forKey:@"MusicSwith"];
                [settingsDic setValue:@"send_0" forKey:@"sendMsgBoolKey"];//添加发消息声音提示为YES
                [settingsDic setValue:[NSNumber numberWithBool:YES] forKey:@"systemset_friendreadstatus"];//发送消息已读状态设置
                [settingsDic setValue:[NSNumber numberWithBool:NO] forKey:@"setFollowsHidden"];//隐藏关注的人，默认为否，不隐藏
                
                [settingsDic setValue:[resDic valueForKey:@"hideme"] forKey:@"hideme"];
                NSMutableDictionary *addDic = [NSMutableDictionary dictionaryWithDictionary:resDic];
                [addDic setValue:settingsDic forKey:@"settings"];
                [UserDefaults setValue:addDic forKey:MyAppDataManager.useruid];
            }
            else
            {
                NSMutableDictionary *settingsDic = [NSMutableDictionary dictionaryWithDictionary:[[UserDefaults valueForKey:MyAppDataManager.useruid] valueForKey:@"settings"]];
                [settingsDic setValue:[resDic valueForKey:@"hideme"] forKey:@"hideme"];
                NSMutableDictionary *addDic = [NSMutableDictionary dictionaryWithDictionary:resDic];
                [addDic setValue:settingsDic forKey:@"settings"];
                [UserDefaults setValue:addDic forKey:MyAppDataManager.useruid];
                
            }
            
            //添加三个系统通知设置
            if(![[[UserDefaults valueForKey:MyAppDataManager.useruid] valueForKey:@"settings"] valueForKey:@"visitYouNotification"])
            {
                NSMutableDictionary *settingsDic = [NSMutableDictionary dictionaryWithDictionary:[[UserDefaults valueForKey:MyAppDataManager.useruid] valueForKey:@"settings"]];
                
                [settingsDic setValue:[NSNumber numberWithBool:YES] forKey:@"visitYouNotification"];   //接收“我查看了你的个人资料”通知
                [settingsDic setValue:[NSNumber numberWithBool:YES] forKey:@"followYouNotification"];  //接收“我关注了你”通知
                [settingsDic setValue:[NSNumber numberWithBool:YES] forKey:@"takeCareNotification"];   //接收新用户注册通知
                
                
                NSMutableDictionary *addDic = [NSMutableDictionary dictionaryWithDictionary:[UserDefaults valueForKey:MyAppDataManager.useruid]];
                [addDic setValue:settingsDic forKey:@"settings"];
                [UserDefaults setValue:addDic forKey:MyAppDataManager.useruid];
            }
            
            //是否删除聊天表
            if (![[[[UserDefaults valueForKey:MyAppDataManager.useruid] valueForKey:@"settings"] valueForKey:@"onceRun"] boolValue])
            {
                //保存版本号
                NSString  *versonPath =[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0] stringByAppendingPathComponent:@"data.dat"];
                
                NSMutableDictionary * versonDic = [NSKeyedUnarchiver unarchiveObjectWithFile:versonPath];
                NSString * versonString = [versonDic valueForKey:MyAppDataManager.useruid];
                NSInteger versonNum = [versonString integerValue];
                
                //当前版本
                versonString = MyAppDataManager.newVersionNumber;
                versonString = [versonString stringByReplacingOccurrencesOfString:@"." withString:@""];
                
                NSInteger newVerson = [[MyAppDataManager.newVersionNumber stringByReplacingOccurrencesOfString:@"." withString:@""] integerValue];
                
                if (newVerson > 100)
                {
                    newVerson /= 10;
                }
                if (versonNum > 100)
                {
                    versonNum /= 10;
                }
                
                if (versonNum < newVerson )//1.5.1 :15;1.6.1:16；如果1.6：16，1.6.1：16；两者相等，如果没有旧版本号，说明是新登录的，直接更新
                {
                    //1备份数据库（chat_130026_0 被分为chat_130026_0_bak,talkPeoples130026被分为talkPeoples130026_bak等等）
                    BOOL bl = [BanBu_UpgradeDataBase backupDB];
                    if (bl)
                    {
                        NSLog(@"数据库升级完成");
                    }
                }
                
                //保存当前本版号
                [versonDic setValue:versonString forKey:MyAppDataManager.useruid];
                NSData *listData=[NSKeyedArchiver archivedDataWithRootObject:versonDic];
                [listData writeToFile:versonPath atomically:YES];
                
                NSMutableDictionary * settingDic = [NSMutableDictionary dictionaryWithDictionary:[[UserDefaults valueForKey:MyAppDataManager.useruid] valueForKey:@"settings"]];
                
                [settingDic setValue:[NSNumber numberWithBool:1] forKey:@"onceRun"];
                NSMutableDictionary * dic =[NSMutableDictionary dictionaryWithDictionary:[UserDefaults valueForKey:MyAppDataManager.useruid]];
                [dic setValue:settingDic forKey:@"settings"];
                
                [UserDefaults setValue:dic forKey:MyAppDataManager.useruid];
            }
            
            //创建10张聊天记录表
            [MyAppDataManager initDetailChatMessageTable];
            
            [UserDefaults setValue:MyAppDataManager.useruid forKey:@"myID"];
            [UserDefaults synchronize];
            [UserDefaults setValue:[resDic valueForKey:@"friendlist"] forKey:FriendShip];
            
            NSMutableDictionary *pars = [NSMutableDictionary dictionaryWithCapacity:2];
            if(_bindType == 1)
            {
                [pars setValue:@"facebook" forKey:@"bindto"];
                [pars setValue:[NSString stringWithFormat:@"%@,%@",[UserDefaults valueForKey:@"FBAccessToken"],[UserDefaults valueForKey:@"FBUser"]] forKey:@"bindstring"];
            }
            else if(_bindType == 2)
            {
                [pars setValue:@"twitter" forKey:@"bindto"];
                [pars setValue:[NSString stringWithFormat:@"%@,%@,%@",[UserDefaults valueForKey:@"TAccessToken"],[UserDefaults valueForKey:@"TAccessTokenSecret"],[UserDefaults valueForKey:@"TUser"]] forKey:@"bindstring"];
            }
            
            [AppComManager getBanBuData:BanBu_Set_User_accountbind par:pars delegate:self];
        }
        else
        {
            [MyAppDataManager.regDic setValue:[NSNumber numberWithInteger:_bindType] forKey:@"bindtype"];
            BanBu_RegViewController *reg = [[BanBu_RegViewController alloc] init];
            [self.navigationController pushViewController:reg animated:YES];
            [reg release];
        }
    }
    else if([AppComManager respondsDic:resDic isFunctionData:BanBu_Set_User_accountbind])
    {
        NSMutableDictionary *uidDic = [NSMutableDictionary dictionaryWithDictionary:[UserDefaults valueForKey:MyAppDataManager.useruid]];
        [uidDic setValue:[resDic valueForKey:@"bindlist"] forKey:@"bindlist"];
        [UserDefaults setValue:uidDic forKey:MyAppDataManager.useruid];
        [UserDefaults synchronize];
        
        BanBu_AppDelegate *delegate = (BanBu_AppDelegate *)[UIApplication sharedApplication].delegate;
        delegate.logined = YES;
        [delegate setViewController:YES];
    }
}




@end
